package deployr.core;

import java.util.*;

import deployr.domain.*;

public class ExportProject {
	private final StringBuilder stringBuilder = new StringBuilder();

	public ExportProject(final IProject project) {
		token("project");
		token(project.getProjectKey());
		token(project.getGroupId());
		token(project.getArtifactId());
		token(project.getVersion());
		token(Dates.formatMMddyyyyHHmmss(project.getLastUpdated()));
		token(project.getPath());

		final Iterator<IUpdate> updates = project.findUpdates().iterator();

		while (updates.hasNext()) {
			endLine();
			append(new ExportUpdate(updates.next()).toString());
		}

	}

	private void endLine() {
		stringBuilder.append("\n");
	}

	private void append(final String string) {
		stringBuilder.append(string);
	}

	private void token(final String string) {
		stringBuilder.append(string).append(":");
	}

	@Override
	public String toString() {
		return stringBuilder.toString();
	}

}
